#ifndef EDITWIDGET_H
#define EDITWIDGET_H

#include <QWidget>
#include <QMap>
#include "common.h"
#include "viewobject.h"

class QMenu;
class QAction;
class StructureWidget;

class EditWidget : public QWidget
{
    Q_OBJECT
public:
    explicit EditWidget(QString name, QSize size, QWidget *parent = nullptr);
    ~EditWidget();

public:
    QString  generate_interface(QString&, ObjectInfo, QPoint);
    void savecfg();
    void setPath(QString);
    void setPrefix(QString);
    QString AutoGenerate(QString object_name, QString &struct_show_item_name, QPoint, int w, int h);
    QMap<QString, QString> GenerateForStationView(QString idtype, AutoData* data, Staggered staggered, int station_num, int lineIndex, int startStationId, int stationSpacing, QPoint nameOffset);
    QMap<QString, QString> GenerateForStationViewInterval(QString idtype, AutoData* data, Staggered staggered, int station_num, int nameOffset);
    void updata2downdataPos(int route_id, const ViewObjectInfo *updata);
    QVector<ViewObjectInfo*> GetWidgetVectorData(){return mObjectVector;}
    QString updata2downdata(ViewObjectInfo *updata);
    QString original2mirror(ViewObjectInfo *originaldata, QString nonmirror_name);
    QString CopyArriveFromStationOne(ViewObjectInfo *updata);
    void CopyOneAttribute(const std::string &attribute_name, ViewObjectInfo *from, ViewObjectInfo *to);
    QString GetFileName() {return mFileName;}
    void show_component();
    void xml_to_vector(QString, QString, StructureWidget *struture_widget);
    void ClearVector();
    void ClearMainWayVector();

public slots:
    void slt_list_to_graphics(QString, QString);
    void sltDeleteObject(QString);
    void sltCopyObjectData(QString random);
    void ctrl_select(QString id);
    void slt_find_changed_viewobject(QString);
    void slt_update_to_attribute(QString);

signals:
//    void signal_Attributes(QString, ViewObjectInfo*);
    void sgl_attribute_to_showwidget(QString, ViewObjectInfo*);
    void sgl_update_to_showwidget(QString, ViewObjectInfo*);
    void signal_delete(QString);
    void signalCopy(QString, QString, QString);

protected:
    void keyPressEvent(QKeyEvent *event);
    void mousePressEvent(QMouseEvent *event);
//    void contextMenuEvent(QContextMenuEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

private:
    //此参数记录singleview的个数以便给singleview的name赋值
    int   m_max_single_num;
    int   m_width;
    int   m_height;
    QString mFileName;
    QString mPath;

    QVector<ViewObjectInfo*> mObjectVector;

    QMap<QString, ViewObjectInfo*> tmp_map;//用于复制粘贴
    ViewObjectInfo *mClipboard = NULL;
    QString   mCopyID = "";
    QPoint    mCopyPos;
    QMenu     *right_menu;
    QAction   *action_paste;

    QPoint    m_topLeft;
    QPoint    m_rigntBotttom;

private:
    void CopyData(ViewObjectInfo *info);
    void Paste();
//    void createActions();
    void select_object_by_rect();
};

#endif // EDITWIDGET_H
